/**
 * localstorage封装
 * @author 吴昊
 */

import config from '../config/index'

export default {
    //从localStorage中取值判断
    getStorage(){
        return JSON.parse(window.localStorage.getItem(config.namespace) || "{}")
    },
    //从localStorage中拿任意值
    getItem(key){
        return this.getStorage()[key]
    },
    //给localStorage设置值
    getItem(key,val){
        let storage = this.getStorage();
        storage[key] = val;

        window.localStorage.setItem(config.namespace,JSON.stringify(storage));
    },
    //删除某一个属性值
    clearItem(key){
        let storage = this.getStorage();
        delete storage[key]
        
        window.localStorage.setItem(config.namespace , JSON.stringify(storage));
    },
    //删除所有
    clearAll(){
        window.localStorage.clear();
    }
}